package com.webflux.sample.webfluxmain;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import reactor.core.publisher.Flux;

public class _5_6operator_merge {

  public static void main(String[] args) {
    // merge和mergeSequential操作符用来把多个流合并成一个Flux序列。merge按照所有流中元素的实际产生序列来合并，
    // 而mergeSequential按照所有流被订阅的顺序，以流为单位进行合并。
    Duration du1 = Duration.of(0, ChronoUnit.MILLIS);
    Duration du2 = Duration.of(100, ChronoUnit.MILLIS);
    Duration du3 = Duration.of(50, ChronoUnit.MILLIS);
    System.out.println("step 1");
    Flux.merge(Flux.interval(du1, du2).take(5), Flux.interval(du3, du2).take(5)).toStream().forEach(System.out::println);
    System.out.println("step 2");
    Flux.mergeSequential(Flux.interval(du1, du2).take(5), Flux.interval(du3, du2).take(5)).toStream().forEach(System.out::println);
  }
}
